
#include "BaseHttpClient.h"
#include <iostream>
#include <string>

using namespace std;

#define THIS_FILE	"BaseHttpClient"

BaseHttpClient::BaseHttpClient(Proactor* proactor,char* remoteip,unsigned short remoteport)
	:BaseConnector(proactor,remoteip,remoteport==0?BaseHTTPSession::HTTP_PORT:remoteport)

{
	cout << THIS_FILE << " construct ok!" << endl;
}


BaseHttpClient::~BaseHttpClient()
{
		cout << THIS_FILE << " destruct go!" << endl;
}

pj_bool_t BaseHttpClient::OnDataRead(void *data,pj_size_t size,int status,pj_size_t* remainder)
{
	char* p = (char*)data;
	printf("BaseRtspClient::OnDataRead status=%d size=%d\n",status,size);
	if (TcpSocket::OnDataRead(data,size,status,remainder)!= PJ_TRUE)
		return PJ_FALSE;

	return handleMessage0(p,size,remainder);
	//return PJ_TRUE;
};
pj_bool_t BaseHttpClient::OnDataSend(pj_ioqueue_op_key_t *send_key,int sendsize)
{
	printf("BaseRtspClient::OnDataSend sendsize=%d\n",sendsize);
	return PJ_TRUE;
};
pj_bool_t BaseHttpClient::OnConnect(int status)
{
	printf("BaseHttpClient::OnConnect status=%d\n",status);
	return PJ_TRUE;
};

int BaseHttpClient::sendGetRequest(string& url,string& body)
{
	string req;
	long size = 0;
	makeGetRequest(url,body,req);
	size = req.length();
	return Send(req.c_str(),size);
}
int BaseHttpClient::sendPostRequest(string& url,string& body)
{
	string req;
	long size = 0;
	makePostRequest(url,body,req);
	size = req.length();
	return Send(req.c_str(),size);
}
int BaseHttpClient::sendPutRequest(string& url,string& body)
{
	string req;
	long size = 0;
	makePutRequest(url,body,req);
	size = req.length();
	return Send(req.c_str(),size);
}
int BaseHttpClient::sendDeleteRequest(string& url,string& body)
{
	string req;
	long size = 0;
	makeDeleteRequest(url,body,req);
	size = req.length();
	return Send(req.c_str(),size);
}
